﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyTest {

    /// <summary>
    /// Checkbox object.
    /// </summary>
    public class CheckBox {

        /// <summary>
        /// Container in which to search for this CheckBox element.
        /// </summary>
        private Focus Focus { get; set; }

        /// <summary>
        /// String representing the Document Element to be searched for.
        /// </summary>
        private string FindBy { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public CheckBox(string findBy, Focus focus) {
            FindBy = findBy;
            Focus = focus;
        }

        /// <summary>
        /// 
        /// </summary>
        public void SetChecked() {
            Set(true);
        }

        /// <summary>
        /// 
        /// </summary>
        public void SetUnchecked() {
            Set(false);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="isChecked"></param>
        private void Set(bool isChecked) {
            Focus.Go();
            if (Action.IsSelected(FindBy) != isChecked)
                Action.Click(FindBy);
        }

        /// <summary>
        /// 
        /// </summary>
        public void VerifyIsChecked() {
            Assert.IsTrue(Action.IsSelected(FindBy));
        }
        
        /// <summary>
        /// 
        /// </summary>
        public void VerifyIsNotchecked() {
            Assert.IsFalse(Action.IsSelected(FindBy));
        }

        /// <summary>
        /// 
        /// </summary>
        public void VerifyIsDisabled() {
            Assert.IsTrue(Action.IsDisabled(FindBy));
        }

        /// <summary>
        /// 
        /// </summary>
        public void VerifyIsNotDisabled() {
            Assert.IsFalse(Action.IsDisabled(FindBy));
        }
    }
}
